<?php

require_once('constants.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
    ob_implicit_flush(true);
 
	if(!isset($_GET['hp'])) exit();
	$hostport = base64_decode($_GET['hp']);
    if(empty($hostport)) exit();
	
    if($req = file_get_contents("php://input")) 
    {
        if(!empty($req))
        {
            $fp = stream_socket_client("tcp://" . $hostport, $errno, $errstr, 600);
            if ($fp !== FALSE) 
            {
                // Send the original request and wait for the response
                fwrite($fp, $req);	  
                while(($resp = fread($fp, 20480)) !== FALSE)
                {
                    if(empty($resp))
                    {
                        break;
                    }
                    else
                    {
                        echo $resp;
                    }
                }
                fclose($fp);
            }		    
        }
	}
}

?>